
Character = {
		blade: "",
		rot: {x:0,y:0,z:0},
		pos: {x:0,y:-500,z:0},
		bladeReady: false,
		moving: false,
		targetIndex: -1,
		targetPos:{x:"",y:"",z:""},
		load: function(){
			if(typeof this.blade === 'object'){
				scene.remove(this.blade);
			}
			var loader = new THREE.ColladaLoader();
//			var path = "image/woman/models/01.dae";
//			var path = "image/tree/tree.this.blade";
//			var path = "image/yoshi.this.blade"
			var path = "image/blade/blade.dae";
			loader.load( path, function colladaReady( collada ) {
				Character.blade = collada.scene;
				Character.blade.position.y = Character.pos.y;
				
				//this.blade.rotation.x = Math.PI/2;
				//this.blade.rotation.y = Math.PI/2;
				Character.blade.rotation.x = -Math.PI/4;
				Character.blade.scale.x = 5;
				Character.blade.scale.y = 5;
				Character.blade.scale.z = 5;
				World.scene.add( Character.blade );
				Character.bladeReady = true;
			});
		},
		updatePosition: function(){
			
			if(ShootController.weaponType == 1 && !this.moving){
				this.pos.x = PlayMan.pos.x + 5*PlayMan.radius * Math.sin(PlayMan.rot.y + Math.PI*0.1);
				this.pos.z = PlayMan.pos.z + 5*PlayMan.radius * Math.cos(PlayMan.rot.y + Math.PI*0.1);
				this.pos.y = PlayMan.pos.y + 5*PlayMan.radius * Math.sin(PlayMan.rot.x)-50;
				
				Character.blade.position.set(0,0,0);
				//Character.blade.rotation.y = PlayMan.rot.y;
				Character.blade.rotation.x =  -Math.PI*0.4* (1-PlayMan.rot.y + Math.PI/(0.5*Math.PI));	
				Character.blade.rotation.z = -Math.PI*0.4 * (PlayMan.rot.y-Math.PI) /(0.5*Math.PI);

				Character.blade.position.set(this.pos.x,this.pos.y,this.pos.z);
			}else if(ShootController.weaponType == 0){
				Character.blade.position.set(0, -500, 0);
			}
		},
		rotate: function(){
			this.rot.z += (Math.PI/3) % (2*Math.PI);
			Character.blade.rotation.z = this.rot.z;
			
		},
		
		move: function(){
			
			if(this.moving){
				Character.blade.scale.x = 50;
				Character.blade.scale.y = 50;
				Character.blade.scale.z = 50;
				var x, y, z, k;
				if(this.targetIndex == -1){
					k = 0.00005;
					if(this.targetPos.x == "" && this.targetPos.y == "" && this.targetPos.z == ""){
						this.targetPos.x = CameraController.lookAtPos.x;
						this.targetPos.y = CameraController.lookAtPos.y;
						this.targetPos.z = CameraController.lookAtPos.z;
					}
					x = this.targetPos.x;
					y = this.targetPos.y;
					z = this.targetPos.z;
				}else{
					x = EnemyModel[this.targetIndex].pos.x;
					y = EnemyModel[this.targetIndex].pos.y;
					z = EnemyModel[this.targetIndex].pos.z;
					k = 0.3;
				}
				this.pos.x += k*(x-this.pos.x) ;
				this.pos.y += k*(y-this.pos.y) ;
				this.pos.z += k*(z-this.pos.z) ;
//				console.log(this.pos.x);
				Character.blade.position.set(this.pos.x,this.pos.y,this.pos.z);
				if((this.pos.x - PlayMan.pos.x)*(this.pos.x - PlayMan.pos.x) + (this.pos.y - PlayMan.pos.y)*(this.pos.y - PlayMan.pos.y) +
						(this.pos.z - PlayMan.pos.z)*(this.pos.z - PlayMan.pos.z) > 1000000000)
					{
						console.log("fly too far away");
						this.moving = false;
						this.targetPos.x = "";
						this.targetPos.y = "";
						this.targetPos.z = "";
						Character.blade.scale.x = 5;
						Character.blade.scale.y = 5;
						Character.blade.scale.z = 5;
//						Character.blade.position.set(0,-500,0);
						this.updatePosition();
					}
				if((this.pos.x - x)*(this.pos.x - x) + (this.pos.y - y)*(this.pos.y -y) +(this.pos.z-z) < 10000){
					console.log("blade shoot...");
					Character.blade.position.set(0,-500,0);
					this.targetPos.x = "";
					this.targetPos.y = "";
					this.targetPos.z = "";
					Character.blade.scale.x = 5;
					Character.blade.scale.y = 5;
					Character.blade.scale.z = 5;
					this.moving = false;
					this.updatePosition();
					Enemy.updateSingle(this.targetIndex,"c");
				};
				
				
			}
			
		}
}